package com.songtech.uitest.cases;

import com.songtech.uitest.components.IBrowserDriverFactory;
import com.songtech.uitest.entities.Indent;
import com.songtech.uitest.module.propose.GetTowerId;
import com.songtech.uitest.module.propose.PickupMobileID;
import com.songtech.uitest.module.propose.AddTower;
import com.songtech.uitest.module.propose.ProposeAudit;
import com.songtech.uitest.module.propose.ProposeSubmit;
import com.songtech.uitest.module.propose.UndertakeTower;
import com.songtech.uitest.module.screen.ScreenAudit;
import com.songtech.uitest.module.screen.ScreenSubmit;
import com.songtech.uitest.module.screen.ScreenTower;
import com.songtech.uitest.resources.ServerResource;
import com.songtech.uitest.util.Assertion;
import com.songtech.uitest.util.ConfigLoader;
import com.songtech.uitest.util.RollbackHelper;
import com.songtech.uitest.util.SumUpHelper;
import org.openqa.selenium.By;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

/**
 * 这是传统TestNG编写流程的例子，留作参考，未使用。
 */
@ContextConfiguration(locations = {"classpath:spring-test-config.xml"})
public class TestRegularFlow extends AbstractTestNGSpringContextTests {

	@Autowired
	@Qualifier("browserDriver")
	private IBrowserDriverFactory driverCreater;

	@Autowired
    private RollbackHelper rollbackHelper;

	@Autowired
	private ServerResource serverResource;

	@Autowired
	private Indent indent;

	@Autowired
	private AddTower addTower;

	@Autowired
	private PickupMobileID pickupMobileID;

	@Autowired
	private ProposeSubmit proposeSubmit;

	@Autowired
	private ProposeAudit proposeAudit;

	@Autowired
	private GetTowerId getTowerId;

	@Autowired
	private UndertakeTower undertakeTower;

	@Autowired
	private ScreenTower screenTower;

	@Autowired
	private ScreenSubmit screenSubmit;

	@Autowired
	private ScreenAudit screenAudit;

	@Autowired
	private SumUpHelper sumUpHelper;

	@Autowired
    private ConfigLoader configLoader;

	
	@BeforeClass
	public void init() {
        configLoader.loadFromFile("customFlow1.xls");
		//下边的流程也要和wholeFlow的一致才行，否则kakong无法作正确逻辑判断
		indent.setFlow("01100,02100,03100");
		indent.setStepPosition(0);
	}

	@BeforeMethod
	public void beforeMethod() throws Exception{
		rollbackHelper.rollbackCurrentDriverToInit();
	}


	@Test(enabled=false, priority = 0)
	public void testLogin() throws Exception {
		String loginName = driverCreater.getMainDriver().findElement(By.cssSelector("li.welcome")).findElement(By.tagName("em")).getText();
		Assertion.verifyEquals("aaa", serverResource.getUserName(), false, "登录名与期望不符！");
		System.out.println("---------------------验证登录名的断言之后的内容");
	}


	//注意：priority越小优先级越高，越先执行
	@Test(enabled=true, priority = 1)
	public void testAddOneTower() throws Exception{
		addTower.addOneTower("00");
		pickupMobileID.pickupMobileID("00");

	}


	@Test(enabled=true, dependsOnMethods={"testAddOneTower"}, priority = 2)
	public void testProposeSubmit() throws Exception {
		proposeSubmit.proposeOneSubmit("00");

	}

/*
	@Test(enabled=true, dependsOnMethods={"testProposeSubmit"})
	public void testProposeAudit() throws Exception{
		//这里的flow参数类似"00,01",一次性写多级审批的流程。
		// 一旦出现"10"不同意的话，流程就得手动控制，得再写一个测试方法，重新写proposeOneSubmit
        rollbackHelper.run(proposeAudit, "proposeOneAudit", "01");

	}

	@Test(enabled=true, dependsOnMethods={"testProposeAudit"})
	public void testGetTowerId() throws Exception {
		getTowerId.getTowerId("00");

	}

	@Test(enabled=true, dependsOnMethods={"testGetTowerId"})
	public void testUndertakeTower() throws Exception {
		undertakeTower.undertakeTower("00");

	}

	@Test(enabled=true, dependsOnMethods={"testUndertakeTower"})
	public void testScreenTower() throws Exception {
		screenTower.screenTower("00");

	}

	@Test(enabled=true, dependsOnMethods={"testScreenTower"})
	public void testScreenSubmit() throws Exception {
		screenSubmit.screenOneSubmit("00");

	}

	@Test(enabled=true, dependsOnMethods={"testScreenSubmit"})
	public void testScreenAudit() throws Exception {
		//这里的flow参数类似"00,01",一次性写多级审批的流程。
		// 一旦出现"10"不同意的话，流程就得手动控制，得再写一个测试方法，重新写proposeOneSubmit
		rollbackHelper.run(screenAudit, "screenOneAudit", "01");

	}

*/
	@AfterClass
    public void tearDown() {
		logger.info("配置流程运行完毕。");
		logger.info("单子当前值：" + indent.getMobileId() +","+ indent.getTowerId() +","+ indent.getCurrentBuildType() +",流程下标位置："+ indent.getStepPosition());

		sumUpHelper.printResult();
		sumUpHelper.clearResult();

	}


}
